#pragma once
#include "BasicFunction.h"
using namespace std;

class CHebbian
{
public:
	//constructor
	CHebbian(int n_input, int n_output);
	CHebbian(string filepath);
public:
	//train the network
	void			NetTraining(double* c_input, double* c_output, int* s_input, int* s_output, int trainNum);
	//update weight
	void			UpdateWeight(double c_input, double c_output, int cur_input, int cur_output);
	//find the most associated output
	int				NetFindInput(int cur_output);
	//find the most associated input
	int				NetFindOutput(int cur_input);
	//associated input with output and output with input
	void			NetAssociated(void);
	//set learning rate
	void			NetSetLearningRate(double lr);
	//destroy the network
	bool			NetDestroy(void);
	//rescale the values of Hebbian links
	void			NetRescale(void);
	//get the hebbian link
	double**		NetGetHebbian(void);
	//load the hebbian from a matrix
	void			NetLoadFromMatrix(double** m_Double, int m_Size1, int m_Size2);
	//Save the hebbian links to file
	void			NetSaveToFile(string filename);

private:

	double**		c_hebbian;				//the hebbian linke with i, j input output
											//dimension and k dimension input and j dimension output
	int				n_netinput;				//number of input nodes
	int				n_netoutput;			//number of output nodes
	double			LearningRate;			//the learning factor
	int*			ass_netinput;			//associated output for inputs
	int*			ass_netoutput;			//associated input for outputs
	bool			status_trained;			//flag indicating if network is trained
	bool			status_associated;		//flag indicating if network is associated
	bool			status_loaded;			//flag indicating if the network is loaded from data
	double			m_Max;					//maximum for the scale vector
	double			m_Min;					//minimum for the scale vector
	
	CBasicFunction	bf;

public:
	~CHebbian(void);
};
